package com.yxzr.youyou.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yxzr.youyou.R;
import com.yxzr.youyou.VideoDetailActivity;
import com.yxzr.youyou.bean.HotSearchBean;

import java.util.ArrayList;
import java.util.List;

public class HotSearchAdapter extends RecyclerView.Adapter<HotSearchAdapter.ViewHolder> {
    private Context mContext;
    private List<HotSearchBean.DataBean> list = new ArrayList<>();
    public HotSearchAdapter(Context context,List<HotSearchBean.DataBean> list){
        this.mContext = context;
        this.list = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.hotsearch_adapter_layout,parent,false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.hotsearch_text.setText(list.get(position).getTitle());
        holder.hotsearch_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, VideoDetailActivity.class);
                intent.putExtra("id",list.get(position).getId());
                intent.putExtra("index",Integer.parseInt(list.get(position).getIs_vip()));
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private TextView hotsearch_text;
        public ViewHolder(View itemView) {
            super(itemView);
            hotsearch_text = itemView.findViewById(R.id.hotsearch_text);
        }
    }
}
